from django.contrib import admin

# Register your models here.
from .models import Question, Choice


class ChoiceInline(admin.TabularInline):  # 定义内联对象 StackedInline or TabularInline
    model = Choice
    extra = 3


class QuestionAdmin(admin.ModelAdmin):
    fieldsets = [('Question text', {'fields': ['question_text']}),  # 分组Question text
                 ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']})]  # 分组Date information
    inlines = [ChoiceInline]  # 定义子对象的引用
    list_display = ('question_text', 'pub_date', 'was_published_recently')  # 定义列表中显示的字段
    list_filter = ['pub_date']  # 根据pub_date进行快速过滤
    search_fields = ['question_text']


admin.site.register(Question, QuestionAdmin)
admin.site.register(Choice)
